package it.polimi.digitalstate.entities;

import it.polimi.digitalstate.dto.IDataTransferObject;
import it.polimi.digitalstate.dto.JoinrequestDTO;
import it.polimi.digitalstate.entities.Citizen;
import it.polimi.digitalstate.entities.Party;
import it.polimi.digitalstate.manager.DTOEntityTransformer;

import java.io.Serializable;
import java.lang.String;
import java.sql.Date;

import javax.persistence.*;

import it.polimi.digitalstate.dto.JoinVoteDTO;
/**
 * Entity implementation class for Entity: joinvote
 *
 */
@Entity
@NamedQueries(value = { 
		@NamedQuery(name = "joinvote_getByID", query = "select j from JoinVote j where j.id = :id" ),
		@NamedQuery(name = "joinvote_getByCitizen", query = "select j from JoinVote j where j.citizen = :citizen" ),
		@NamedQuery(name = "joinvote_getOnJoinrequest", query = "select j from JoinVote j where j.joinrequest = :joinrequest" ),
		@NamedQuery(name = "joinvote_votedbefore", query = "select j from JoinVote j where j.citizen = :citizen and j.joinrequest = :joinrequest" ),
		@NamedQuery(name = "joinvote_getcountofjoinrequest", query = "select count(j) from JoinVote j where j.joinrequest = :joinrequest and j.approval = :approval" ),

		})
/*@Table(uniqueConstraints= @UniqueConstraint(columnNames = {"citizen", "election"})) /*only one request per election*/ 
public class JoinVote implements Serializable , IEntity {
	//TODO create the DTO
	//TODO set a Constructor with a DTO and set a method that retrive the DTO
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private int id;
	@JoinColumn(nullable=false)
	private Citizen citizen;
	@JoinColumn(nullable=false)
	private Joinrequest joinrequest;
	@JoinColumn(nullable=false)
	private boolean approval;
	private static final long serialVersionUID = 1L;

	public JoinVote() {
		super();
	}   
	public JoinVote(Citizen citizen, Joinrequest joinrequest, Boolean approval){
		super();
		this.citizen = citizen;
		this.joinrequest=joinrequest;
		this.approval=approval;
	}
	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}   
	public Citizen getCitizen() {
		return this.citizen;
	}

	public void setCitizen(Citizen citizen) {
		this.citizen = citizen;
	}   
	public Joinrequest getJoinrequest() {
		return joinrequest;
	}
	public void setJoinrequest(Joinrequest joinrequest) {
		this.joinrequest = joinrequest;
	}
	public Boolean getApproval() {
		return approval;
	}
	public void setApproval(Boolean approval) {
		this.approval = approval;
	}
	
	@Override
	public IDataTransferObject getDTO() {
		EntityManager em;
		return new JoinVoteDTO (id, citizen.getDTO(), (JoinrequestDTO)joinrequest.getDTO(), approval);
	}
	
   
}
